package com.ig.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ig.business.BookInfoManager;
import com.ig.model.Book;

/**
 * BookInfoServlet controls & provides the responses to All user requests
 * 
 * @author skodali
 * 
 */
public class BookInfoServlet extends HttpServlet {

	RequestDispatcher dispatcher;

	public void init(ServletConfig config) throws ServletException {
		// can configure loggers & schedulers here
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		res.setContentType("text/plain");
		String ean = req.getParameter("ean");
		// gets Book Info from Book Manager.
		Book book = BookInfoManager.getBookInfo(ean.trim());
		req.getSession().setAttribute("book", book);
		if (book == null)
			req.setAttribute("noBookInfo", "noBookInfo");
		dispatcher = req.getRequestDispatcher("/jsp/bookInfo.jsp");
		dispatcher.forward(req, res);

	}

}
